import COS from "cos-js-sdk-v5";

export const cos = new COS({
	SecretId: "AKID3va3ITRCoESTHsGQN7d4ISPGuLYBh187",
	SecretKey: "ub5NSL6g3EEtPinfKrBID1j5PYZRK2Xt",
});

export async function download(url: string, name: string) {
	try {
		// 请求url
		const response = await fetch(url);
		const blob = await response.blob();
		const downloadUrl = URL.createObjectURL(blob);
		// 创建A标签
		const a = document.createElement("a");
		a.href = downloadUrl;
		a.download = name;
		document.body.appendChild(a);
		a.click();
		document.body.removeChild(a);
		URL.revokeObjectURL(downloadUrl);
	} catch (error) {
		console.log("🚀 ~ download ~ error:", error);
	}
}
